package com.qidian.mes.util.pojo;

import com.qidian.mes.util.QdConstant;

/**
 * @Author 戴着假发的程序员
 * @Company 起点编程
 * @Description
 * @Time 2024/3/29 11:39
 */
public class QdResult <T>{
    private int code;
    private String msg;
    private T data;

    public QdResult() {
    }
    public QdResult(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T> QdResult<T> isSuccess(int result){
        return  result == 1 ? success() : error();
    }

    public static <T> QdResult<T> success(T data){
        return new QdResult<>(QdConstant.RESPONSE_STATUS_OK,"success",data);
    }
    public static <T> QdResult<T> success(String msg,T data){
        return new QdResult<>(QdConstant.RESPONSE_STATUS_OK,msg,data);
    }
    public static <T> QdResult<T> success(String msg){
        return new QdResult<>(QdConstant.RESPONSE_STATUS_OK,msg,null);
    }
    public static <T> QdResult<T> success(){
        return new QdResult<>(QdConstant.RESPONSE_STATUS_OK,null,null);
    }

    public static <T> QdResult<T> error(int code,String msg){
        return new QdResult<>(code,msg,null);
    }
    public static <T> QdResult<T> error(int code,String msg,T data){
        return new QdResult<>(code,msg,data);
    }
    public static <T> QdResult<T> error(String msg){
        return new QdResult<>(QdConstant.RESPONSE_STATUS_ERROR,msg,null);
    }
    public static <T> QdResult<T> error(){
        return new QdResult<>(QdConstant.RESPONSE_STATUS_ERROR,null,null);
    }


    public static <T> QdResult<T> duplicate(String msg,T data){
        return new QdResult<>(QdConstant.RESPONSE_STATUS_DUPLICATE,msg,data);
    }
    public static <T> QdResult<T> duplicate(String msg){
        return new QdResult<>(QdConstant.RESPONSE_STATUS_DUPLICATE,msg,null);
    }
    public static <T> QdResult<T> duplicate(){
        return new QdResult<>(QdConstant.RESPONSE_STATUS_DUPLICATE,"",null);
    }


    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
